import 'package:car_map/widget/load_image.dart';
import 'package:flutter/material.dart';
import 'fragment/grouping_page.dart';
import 'fragment/monitor_page.dart';
import 'fragment/more_page.dart';
import 'fragment/square_page.dart';
import 'fragment/statistics_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class IndexPage extends StatefulWidget {
  @override
  _indexState createState() => _indexState();
}

class _indexState extends State<IndexPage> {
  int currentIndex = 0; //初始下标

  List<Widget> widgetLis = new List();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    widgetLis
      ..add(MonitorPage())
      ..add(GroupingPage())
      ..add(StatisticsPage())
      ..add(SquarePage())
      ..add(MorePage());
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    return Scaffold(
      body: IndexedStack(
        index: currentIndex,
        children: widgetLis,
      ),
      bottomNavigationBar: BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
              icon: LoadAssetImage(
                currentIndex==0?"home/ic_more":"home/ic_more_no",
                width: ScreenUtil().setWidth(50.0),
                height: ScreenUtil().setHeight(50.0),
              ),
              title: Text('监控')),
          BottomNavigationBarItem(
              icon: LoadAssetImage(
                currentIndex==1?"home/ic_grouping":"home/ic_grouping_no",
                width: ScreenUtil().setWidth(50.0),
                height: ScreenUtil().setHeight(50.0),
              ),
              title: Text('分组')),
          BottomNavigationBarItem(
              icon: LoadAssetImage(
                currentIndex==2?"home/ic_statistics":"home/ic_statistics_no",
                width: ScreenUtil().setWidth(50.0),
                height: ScreenUtil().setHeight(50.0),
              ),
              title: Text('统计')),
          BottomNavigationBarItem(
              icon: LoadAssetImage(
                currentIndex==3?"home/ic_square":"home/ic_square_no",
                width: ScreenUtil().setWidth(50.0),
                height: ScreenUtil().setHeight(50.0),
              ),
              title: Text('广场')),
          BottomNavigationBarItem(
              icon: LoadAssetImage(
                currentIndex==4?"home/ic_monitor":"home/ic_monitor_no",
                width: ScreenUtil().setWidth(50.0),
                height: ScreenUtil().setHeight(50.0),
              ),
              title: Text('更多')),
        ],
        currentIndex: currentIndex,
        type: BottomNavigationBarType.fixed,
        onTap: (int index) {
          setState(() {
            currentIndex = index;
          });
        },
      ),
    );
  }
}
